package com.gx.smart.building.ui.swap.adapter;

import android.content.Context;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.UnderlineSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.gx.smart.base.BaseAdapter;
import com.gx.smart.building.R;
import com.gx.smart.building.databinding.ItemSwapWarningLayoutBinding;
import com.huishi.gx.ib.grpc.lib.ib.admin.schedule.v1.ClickDto;

/**
 * @author: xiaosy
 * 时间: 2022/9/6
 * @Description: java类作用描述
 * @Version: 1.0
 **/
public class SwapWarningAdapter extends BaseAdapter<ClickDto, SwapWarningAdapter.ViewHolder> {

    public SwapWarningAdapter(Context context) {
        super(context);
    }

    @Override
    protected int onBindLayout() {
        return R.layout.item_swap_warning_layout;
    }

    @Override
    protected ViewHolder onCreateHolder(View view) {
        ItemSwapWarningLayoutBinding binding = ItemSwapWarningLayoutBinding.inflate(
                LayoutInflater.from(mContext),
                (ViewGroup) view,
                false
        );
        return new ViewHolder(binding);
    }

    @Override
    protected void onBindData(ViewHolder holder, ClickDto item, int position) {
        SpannableString spannable = new SpannableString(item.getClickName());
        int end = item.getClickName().length();
        spannable.setSpan(
                new UnderlineSpan(),
                0, // start
                end, // end
                Spannable.SPAN_EXCLUSIVE_INCLUSIVE
        );
        holder.binding.title.setText(spannable);
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        private ItemSwapWarningLayoutBinding binding;

        public ViewHolder(@NonNull ItemSwapWarningLayoutBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }
    }
}
